package com.recource.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.recource.dao.UserDao;
import com.recource.dao.UserTypesMapper;
import com.recource.domain.User;
import com.recource.domain.UserTypes;
import com.recource.util.HostHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 *
 */
@Controller
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserTypesMapper userTypesMapper;

    @RequestMapping("/detail")
    public ModelAndView detail(){
        Integer id = hostHolder.getUser().getId();
        List<UserTypes> userTypes = userTypesMapper.selectList(null);

        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.eq(User::getId, id);
        User user = userDao.selectOne(userLambdaQueryWrapper);

        ModelAndView mav = new ModelAndView();
        mav.addObject("user", user);
        mav.addObject("userTypes", userTypes);
        mav.setViewName("/admin/my/detail");
        return mav;
    }

    @Autowired
    HostHolder hostHolder;

    @Autowired
    private UserDao userDao;






}